package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.common.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 套餐逻辑
 * @version v1.0
 * @date 2019/10/13 15:31
 * @description TODO
 **/
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    public static final Logger log = Logger.getLogger(SetmealController.class);

    @Reference
    private SetmealService setmealService;

    //预约
    @RequestMapping("/getSetmeal")
    public Result getSetmeal() {
        try {
            List<Setmeal> list=setmealService.findAll();
            return Result.success(MessageConstant.QUERY_SETMEALLIST_SUCCESS, list);
        } catch (Exception e) {
            log.error("GetSetmeal setmeal error.",e);
            return Result.error(MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }

    //根据套餐id查询套餐信息
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        try {
            Setmeal setmeal=setmealService.findBySetmealId(id);
            return Result.success(MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            log.error("Find setmeal error.",e);
            return Result.error(MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}